package com.xpertline.ui.user;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableModel;

import com.xpertline.ui.util.WindowUtilities;

public class ListUserPane extends JPanel {
	private static final long serialVersionUID = 1L;
	private JTable userTable;
//	private List<User> userList = new ArrayList<User>();
	
	private void initData() {
//		User user1 = new User();
//		user1.setId("1");
//		user1.setUsername("HoangLe");
//		user1.setPassword("123456");
//		user1.setEmail("@@");
//		userList.add(user1);
	}

	/**
	 * Create the panel.
	 */
	public ListUserPane() {
		initData();
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		JPanel panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 0);
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 0;
		gbc_panel.gridy = 0;
		add(panel, gbc_panel);
		panel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
		
		JButton btnShowAll = new JButton("Hi\u1EC7n t\u1EA5t c\u1EA3");
		btnShowAll.setPreferredSize(new Dimension(100, 25));
		btnShowAll.setHorizontalAlignment(SwingConstants.LEFT);
		panel.add(btnShowAll);
		
		JButton btnShowPart = new JButton("Hi\u1EC7n m\u1ED9t ph\u1EA7n");
		btnShowPart.setPreferredSize(new Dimension(120, 25));
		panel.add(btnShowPart);
		
		JButton btnDelete = new JButton("X\u00F3a");
		btnDelete.setPreferredSize(new Dimension(100, 25));
		panel.add(btnDelete);
		
		JButton btnAdd = new JButton("Th\u00EAm");
		btnAdd.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent paramActionEvent) {
				EditUserPane pane = new EditUserPane();
				JFrame jFrame = WindowUtilities.openInJFrame(pane, 750, 500);
				jFrame.setTitle("Phan quyen su dung");
			     WindowUtilities.centerOnScreen(jFrame);
			}
		});
		btnAdd.setPreferredSize(new Dimension(100, 25));
		panel.add(btnAdd);
		
		JScrollPane scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.insets = new Insets(0, 10, 10, 10);
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 1;
		add(scrollPane, gbc_scrollPane);
		
		userTable = new JTable();
		userTable.setRowHeight(20);
		userTable.setColumnSelectionAllowed(true);
		userTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		userTable.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
				{null, null},
			},
			new String[] {
				"T\u00EAn \u0111\u0103ng nh\u1EADp", "Ghi ch\u00FA"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, Object.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		userTable.getColumnModel().getColumn(0).setPreferredWidth(218);
		userTable.getColumnModel().getColumn(1).setPreferredWidth(405);
		scrollPane.setViewportView(userTable);
//		initDataBindings();

	}
//	protected void initDataBindings() {
//		JTableBinding<User, List<User>, JTable> jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ, userList, userTable);
//		//
//		BeanProperty<User, String> userBeanProperty = BeanProperty.create("id");
//		jTableBinding.addColumnBinding(userBeanProperty).setColumnName("ID");
//		//
//		BeanProperty<User, String> userBeanProperty_1 = BeanProperty.create("username");
//		jTableBinding.addColumnBinding(userBeanProperty_1).setColumnName("username");
//		//
//		BeanProperty<User, String> userBeanProperty_2 = BeanProperty.create("password");
//		jTableBinding.addColumnBinding(userBeanProperty_2).setColumnName("password");
//		//
//		BeanProperty<User, String> userBeanProperty_3 = BeanProperty.create("email");
//		jTableBinding.addColumnBinding(userBeanProperty_3).setColumnName("email");
//		//
//		jTableBinding.bind();
//	}
}
